package com.market.controller;



import com.market.Vo.OrderReportVO;
import com.market.Vo.SalesTop10ReportVO;
import com.market.Vo.TurnoverReportVO;
import com.market.Vo.UserReportVO;
import com.market.service.ReportService;
import com.market.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;

@RestController
@RequestMapping("/api")
@Slf4j
public class ReportController {

    @Autowired
    private ReportService reportService;

    @GetMapping("/sales")
    public Result<TurnoverReportVO> turnoverStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate start,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
            ){
        log.info("营业额统计：{},{}",start,end);
        TurnoverReportVO statistics = reportService.getTurnoverStatistics(start, end);
        return Result.success(statistics);
    }


    @GetMapping("/users")
    public Result<UserReportVO> userStatistics(
            @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate start,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        UserReportVO userStatistics = reportService.getUserStatistics(start, end);
        return Result.success(userStatistics);
    }

    @GetMapping("/orders")
   public Result<OrderReportVO> ordersStatistics(
           @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate start,
           @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){

            return Result.success(reportService.getOrdersStatistics(start,end));
   }


   @GetMapping("/ranking")
   public  Result<SalesTop10ReportVO> getTop10(
           @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate start,
           @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
   ){
        return Result.success(reportService.getTop10(start,end));
   }

}
